//
// Created by Administrator on 2020/10/15.
//

#include "../include/nbmApi.h"
#include "../../../../../ccore/sctp/include/sctpApi.h"
#include "nbFsm.h"

int32_t RAN_L3_NBM_Init(void)
{
    int32_t rc;
    uint32_t loop;
    S_RanL3NbInst *pNbInst;

    for (loop = 0; loop < gpRanL3Context->nbNum; loop++)
    {
        pNbInst = &gpRanL3Context->nbInst[loop];
        pNbInst->nbIdx = loop;

        rc = SCTPC_Init(&pNbInst->sctpFd);
        IF_RETURN(!=, O5G_RC_OK, rc, O5G_RC_ER, "RAN_L3_NBM_Init() SCTPC_Init() error!\n");
    }

    rc = RAN_L3_NB_SM_Init();
    IF_RETURN(!=, O5G_RC_OK, rc, O5G_RC_ER, "RAN_L3_NBM_Init() RAN_L3_NB_SM_Init() error!\n");

    return O5G_RC_OK;
}

int32_t RAN_L3_NBM_Final(void)
{
    int32_t rc;
    uint32_t loop;
    S_RanL3NbInst *pNbInst;

    for (loop = 0; loop < gpRanL3Context->nbNum; loop++)
    {
        pNbInst = &gpRanL3Context->nbInst[loop];

        rc = SCTPC_Final(pNbInst->sctpFd);
        IF_RETURN(!=, O5G_RC_OK, rc, O5G_RC_ER, "RAN_L3_NBM_Final() SCTPC_Final() error!\n");
    }

    rc = RAN_L3_NB_SM_Final();
    IF_RETURN(!=, O5G_RC_OK, rc, O5G_RC_ER, "RAN_L3_NBM_Final() RAN_L3_NB_SM_Final() error!\n");

    return O5G_RC_OK;
}

void RAN_L3_NBM_IndProcess(S_OsSelectInd *pIndMsg)
{
    switch (pIndMsg->ind)
    {
    case RAN_L3_INTRA_IND_MSG_NB_FSM_EVT:
        RAN_L3_NB_SM_IndProcess(pIndMsg);
        break;
    default:
        break;
    }
}

void RAN_L3_NBM_MsgProcess(void)
{

}

void RAN_L3_NBM_PrdProcess(void)
{
    RAN_L3_NB_SM_PrdProcess();
}
